﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace HA.Data
{
    public static class TxtCsvFileReader
    {

        public static List<string[]> ReadTxtfile(string filename,char[] split)
        {
            List<string[]> strLst = new List<string[]>();

            if (System.IO.File.Exists(filename) == false) return null;

            try
            {
                StreamReader reader = new StreamReader(filename);

                while (reader.EndOfStream == false)
                {
                    string strLine = reader.ReadLine();

                    string[] arrayStr;
                    if (split != null && split.Length > 0)
                    {
                        arrayStr = strLine.Split(split, StringSplitOptions.RemoveEmptyEntries);
                    }
                    else
                    {
                        arrayStr = new string[1] { strLine };
                    }

                    strLst.Add(arrayStr);

                }

                return strLst;
            }
            catch (Exception ex)
            {
                return null;
            }
            
        }

    }
}
